/*
 * Decompiled with CFR 0_132.
 */
package forward.Module.Modules.Combat;

import java.awt.Color;

import forward.api.EventHandler;
import forward.api.Events.World.EventPacketSend;
import forward.api.Events.World.EventPreUpdate;
import forward.api.Value.Mode;
import forward.Client;
import forward.Module.Module;
import forward.Module.ModuleType;
import forward.Module.Modules.Move.Speed;
import forward.Util.TimerUtil;
import net.minecraft.block.BlockLiquid;
import net.minecraft.client.Minecraft;
import net.minecraft.network.play.client.C02PacketUseEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper;
import net.minecraft.network.play.client.C03PacketPlayer.C04PacketPlayerPosition;
import net.minecraft.network.play.client.C03PacketPlayer.C06PacketPlayerPosLook;

public class Criticals
        extends Module {
    public static Mode mode = new Mode("Mode", "mode", (Enum[]) CritMode.values(), (Enum) CritMode.Jump);
    private TimerUtil timer = new TimerUtil();

    public Criticals() {
        super("Criticals", new String[]{"crits", "crit"}, ModuleType.Combat);
        this.setColor(new Color(235, 194, 138).getRGB());
        this.addValues(this.mode);
    }

    public static boolean isOnWater() {
        double y = Minecraft.thePlayer.posY - 0.03;
        for (int x = MathHelper.floor_double((double) Minecraft.thePlayer.posX); x < MathHelper
                .ceiling_double_int(Minecraft.thePlayer.posX); ++x) {
            for (int z = MathHelper.floor_double((double) Minecraft.thePlayer.posZ); z < MathHelper
                    .ceiling_double_int(Minecraft.thePlayer.posZ); ++z) {
                BlockPos pos = new BlockPos(x, MathHelper.floor_double(y), z);
                if (!(mc.theWorld.getBlockState(pos).getBlock() instanceof BlockLiquid))
                    continue;
                return true;
            }
        }
        return false;
    }

    public static boolean isInLiquid() {
        double y = Minecraft.thePlayer.posY + 0.01;
        for (int x = MathHelper.floor_double((double) Minecraft.thePlayer.posX); x < MathHelper
                .ceiling_double_int(Minecraft.thePlayer.posX); ++x) {
            for (int z = MathHelper.floor_double((double) Minecraft.thePlayer.posZ); z < MathHelper
                    .ceiling_double_int(Minecraft.thePlayer.posZ); ++z) {
                BlockPos pos = new BlockPos(x, (int) y, z);
                if (!(mc.theWorld.getBlockState(pos).getBlock() instanceof BlockLiquid))
                    continue;
                return true;
            }
        }
        return false;
    }

    @EventHandler
    private void onUpdate(EventPreUpdate e) {
        this.setSuffix(this.mode.getValue());
    }

    private boolean canCrit() {
        if (this.mc.thePlayer.onGround && !this.mc.thePlayer.isInWater() && !Client.instance.getModuleManager().getModuleByClass(Speed.class).isEnabled()) {
            return true;
        }
        return false;
    }

    @EventHandler
    private void onPacket(EventPacketSend e) {
        if (e.getPacket() instanceof C02PacketUseEntity && this.canCrit() && this.mode.getValue() == CritMode.Jump&&mc.thePlayer.onGround && ((C02PacketUseEntity) e.getPacket()).getAction() == C02PacketUseEntity.Action.ATTACK && mc.thePlayer.isCollidedVertically ) {
            this.mc.thePlayer.motionY = 0.3999;
        }
        double x = mc.thePlayer.posX;
        double y = mc.thePlayer.posY;
        double z = mc.thePlayer.posZ;
        float yaw = mc.thePlayer.rotationYaw;
        float pitch = mc.thePlayer.rotationPitch;
        if (this.mode.getValue() == CritMode.TestHypixelC04 && this.canCrit()) {
            double[] offsets = new double[]{0.0625, 0.0, 1.0E-4, 0.0};
            int i = 0;
            while (i < offsets.length) {
                mc.netHandler.addToSendQueue(new C04PacketPlayerPosition(x, y + 0.05250000001304, z, false));
                mc.netHandler.addToSendQueue(new C04PacketPlayerPosition(x, y + 0.00150000001304, z, false));
                ++i;
            }
            this.timer.reset();
        }
        if (this.mode.getValue() == CritMode.TestHypixelC06 && this.canCrit()) {
            double[] offsets = new double[]{0.0625, 0.0, 1.0E-4, 0.0};
            int i = 0;
            while (i < offsets.length) {
                mc.netHandler.addToSendQueue(new C06PacketPlayerPosLook(x, y + 0.05250000001304, z, yaw, pitch, false));
                mc.netHandler.addToSendQueue(new C06PacketPlayerPosLook(x, y + 0.00150000001304, z, yaw, pitch, false));
                ++i;
            }
            this.timer.reset();
        }
        if (this.mode.getValue() == CritMode.NCPPacket && this.canCrit()) {
            double[] offsets = new double[]{0.0625, 0.0, 1.0E-4, 0.0};
            int i = 0;
            while (i < offsets.length) {
                mc.netHandler.addToSendQueue(new C06PacketPlayerPosLook(x, y + 0.11, z, yaw, pitch, false));
                mc.netHandler.addToSendQueue(new C06PacketPlayerPosLook(x, y + 0.1100013579, z, yaw, pitch, false));
                mc.netHandler.addToSendQueue(new C06PacketPlayerPosLook(x, y + 0.0000013579, z, yaw, pitch, false));
                ++i;
            }
            this.timer.reset();
        }
    }

    static enum CritMode {
        TestHypixelC04,
        TestHypixelC06,
        NCPPacket,
        Jump;
    }

}

